import { constantRoutes, asyncRoutes } from '@/router'
const state = {
  router: constantRoutes
}
const mutations = {
  // set路由权限
  setRouters(store, payload) {
    store.router = [...constantRoutes, ...payload]
  }
}
const actions = {
  filterRouters({ commit }, menus) {
    // 筛选出有权限的动态路由
    const list = asyncRoutes.filter(key => menus.includes(key.name))
    // 添加动态路由
    commit('setRouters', list)
    return list
  }
}
export default {
  namespaced: true,
  state,
  mutations,
  actions
}
